package com.zhilianbao.leyaogo.view.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhilianbao.leyaogo.R;

/**
 * ClassName: HomeColumnContainer1 <br>
 * Description: <br>
 * Author: Cyarie <br>
 * Created: 2016/11/2 11:06 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class HomeColumnContainer extends BaseContainer<String> {

    private OnItemClickListener mOnItemClickListener;//Item点击事件

    public HomeColumnContainer(Context context) {
        super(context);
    }

    public HomeColumnContainer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.item_home_column;
    }

    /**
     * 设置Item点击事件
     *
     * @param onItemClickListener
     */
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    @Override
    public void initView(View view, int position, String item) {
        ImageView iv = (ImageView) view.findViewById(R.id.iv_column_icon);
        int resId[] = new int[]{R.drawable.new_exclusive, R.drawable.daily_specials, R.drawable.enter_must_buy, R.drawable.recharge_gift};
        iv.setImageResource(resId[position]);
        TextView tv = (TextView) view.findViewById(R.id.tv_column_title);
        tv.setText(item);
        view.setOnClickListener(new TagItemClickListener(position));
    }

    /**
     * 点击事件
     */
    private class TagItemClickListener implements View.OnClickListener {

        private int position;

        public TagItemClickListener(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View view) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(view, position);
            }
        }
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
}
